package com.colin.dubbo.service;

import com.colin.dubbo.business.response.CommonResponse;
import com.colin.dubbo.entity.dto.RequestDto;
import com.colin.dubbo.exception.BusiException;
import com.colin.dubbo.strategy.context.HandleStrategyContext;
import com.colin.dubbo.util.LogUtil;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("baseService")
public class BaseServiceImpl implements BaseService {
    
    @Resource
    private HandleStrategyContext handleStrategyContext;
    
    @Override
    public CommonResponse handle(RequestDto request) {
        CommonResponse response = CommonResponse.success();
        try{

            response = handleStrategyContext.getStrategy(request.getMethod()).handle(request);
            
        }catch (BusiException e){
            response.toBusiError(e.getCode(), e.getMessage());
        } catch (Exception e){
            response.toSysError();
            LogUtil.error("handle_error:", e);
        }
        return response;
    }
}
